#!/usr/bin/env python

import random

class TrainingDataGenerator(object):
    """
        Generates training data for the filter
        @param self: The instance pointer
        @param number: number of training data to generate
    """
    def __init__(self, number):
        self.attributes = ['attribute1', 'attribute2','attribute3']
        self.number = number    

    def generate_training_data(self):
        
        result = {}
        result['noSpam'] = []
        result['spam'] = []
        
        generator = DocumentGenerator(self.attributes)
        
        for i in range(0,self.number):
            
            doc = generator.generate()        
            if (self.is_spam(doc)):
                result['spam'].append(doc)
            else:
                result['noSpam'].append(doc)
            
        
        return result
        
    def get_model_attributes(self):
        return self.attributes
        
    def is_spam(self,doc):
        
        if ((doc['attribute1'] == 1 and doc['attribute2'] == 1 and doc['attribute3'] == 1)):
            return True

        if ((doc['attribute1'] == 1 and doc['attribute2'] == 1 and doc['attribute3'] == 0)):
            return True

        if ((doc['attribute1'] == 0 and doc['attribute2'] == 1 and doc['attribute3'] == 1)):
            return True

        if ((doc['attribute1'] == 1 and doc['attribute2'] == 0 and doc['attribute3'] == 1)):
            return True

        return False
                    
                
class DocumentGenerator(object):
    """
        Generates a random document
    """
    def __init__(self, attributes):
        self.attributes = attributes;            
        
    def generate(self):
        document = {}

        for att in self.attributes:
            document[att] = random.randint(0,1)
                        
        return document
     
    """
        Generates a set of random documents
    """   
    def generateSet(self,number):

        result = []
        
        for i in range(0,number):
            result.append(self.generate())

        return result